/*
 * Copyright (c) 2012-2015 The original author or authors
 * ------------------------------------------------------
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * and Apache License v2.0 which accompanies this distribution.
 *
 * The Eclipse Public License is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * The Apache License v2.0 is available at
 * http://www.opensource.org/licenses/apache2.0.php
 *
 * You may elect to redistribute this code under either of these licenses.
 */
package com.chinamobile.iot.mqtt.spi.security;


/**
 * ACL checker.
 * <p>
 * Create an authorizator that matches topic names with same grammar of subscriptions.
 * The # is always a terminator and its the multilevel matcher.
 * The + sign is the single level matcher.
 *
 * @author andrea
 */
public interface IAuthorizator {

    /**
     * Ask the implementation of the authorizator if the topic can be used in a publish.
     */
    boolean canWrite(String topic, String clientId, String mqttId, String content);

    /**
     * ask the implementation of the authorizator if the topic can be read by clientId
     *
     * @param topic    the topic filter
     * @param clientId the clientId that want to subscribe the topic
     * @param mqttId   the mqtt of the clientId
     * @return
     */
    boolean canRead(String topic, String clientId, String mqttId);

    /**
     * retrieve the real mqttid that proxy the @param mqttId
     *
     * @param mqttId the mqttId
     * @param type   "read", "write"
     * @return if exist return the real mqttId, otherwise return null
     */
    String getProxy(String mqttId, String type);

    /**
     * remove all information that mqttid proxy
     *
     * @param mqttId the mqttId
     */
    void cleanProxy(String mqttId);

    /**
     * get the default cmd topic when the broker want to publish message to some client
     *
     * @param clientId the clientId
     * @param mqttId   the mqttId
     * @return the topic
     */
    String getCmdTopic(String clientId, String mqttId);
}
